package com.hmall.search.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建EsClient
 * @Author:篍
 * @Date: 2025/09/10 15:00
 * @Description:
 */

@Configuration
public class EsConfig {
    @Bean
    public ElasticsearchClient esClient(){
        // 创建 ObjectMapper 实例
        ObjectMapper objectMapper = new ObjectMapper();
        // 添加 JavaTimeModule 以支持 LocalDateTime 类型
        objectMapper.registerModule(new JavaTimeModule());
        return new ElasticsearchClient(
                new RestClientTransport(
                        RestClient.builder(new HttpHost("192.168.101.68",9200)).build(),new JacksonJsonpMapper(objectMapper)));
    }
}
